package com.junbao.message.infrastructure.queue.message;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.junbao.message.domain.enums.ProducerName;
import com.junbao.message.domain.model.NotifyMessage;
import com.junbao.message.infrastructure.core.RequestDto;
import com.junbao.message.infrastructure.core.dispatcher.MessageDeadDisruptor;
import com.junbao.message.infrastructure.core.dispatcher.MessageRetrySendDisruptor;
import com.junbao.message.infrastructure.queue.AbstractTask;

@SuppressWarnings("all")
public class RetryMessageTask extends AbstractTask{
    
    private static final Logger LOGGER = LoggerFactory.getLogger(RetryMessageTask.class);
    
    private  NotifyMessage message;
    
    private MessageRetrySendDisruptor messageRetrySendDisruptor;
    
    private MessageDeadDisruptor messageDeadDisruptor;
    
    public RetryMessageTask(String id,NotifyMessage message) {
        super(id,message.getNextRetryExecuteTime());
        this.message = message;
        this.messageRetrySendDisruptor = MessageRetrySendDisruptor.instance();
        this.messageDeadDisruptor = MessageDeadDisruptor.instance();
    }
 
    @Override
    public void run() {
        if (!message.isGreaterThanMaxRetryCount() && message.meesageIsCanSend()) {
            messageRetrySendDisruptor.getMessageProducer(ProducerName.MESSAGE_RETRY_SEND_PRODUCER)
            .sendData(new RequestDto<NotifyMessage>(message));
            return;
        }else if(!message.meesageStatusIsDead()) {
            messageDeadDisruptor.getMessageProducer(ProducerName.MESSAGE_DEAD_PRODUCER)
            .sendData(new RequestDto<NotifyMessage>(message));
            return;
        }
    }
 
}
